package org.ring.rpc;

import org.ring.common.URL;
import org.ring.common.transport.Connection;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * @since 2024-10-28 20:15
 */
public class DefaultInvoker<T> implements Invoker {

    private Connection connection;

    private URL url;

    public DefaultInvoker(URL url, Connection connection) {
        this.url = url;
        this.connection = connection;
    }

    @Override
    public Object invoke(Invocation invocation) {
        CompletableFuture cf = connection.request(invocation, 1000, null);
        try {
            return cf.get();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } catch (ExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public URL url() {
        return null;
    }
}
